package exception;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Student {
    private Integer sNo;
    private String name;
    private Character sex;
    private Date birthday;
    private double score;

    public Student() {
    }

    public Student(Integer sNo, String name, Character sex, Date birthday, double score) {
        this.sNo = sNo;
        this.name = name;
        this.sex = sex;
        this.birthday = birthday;
        this.score = score;
    }

    public void input() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("信息录入函数.....");
        System.out.println("请输入学号：");
        this.sNo = scanner.nextInt();
        System.out.println("请输入姓名：");
        this.name = scanner.next();
        System.out.println("请输入性别：");
        try {
            this.sex = scanner.next().charAt(0);
            if (sex != '男' && sex != '女')
                throw new SexException();
        } catch (SexException e) {
            e.printStackTrace();
        }

        System.out.println("请输入生日（格式为：2001-08-25）：");
        try {
            this.birthday = new SimpleDateFormat("yyyy-MM-dd").parse(scanner.next());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        System.out.println("请输入分数：");
        this.score = scanner.nextDouble();
    }

    public void display() {
        System.out.println(toString());
    }

    public void sayHello() {
        System.out.println("你好呀，兰兰宝贝");
    }

    public Integer getsNo() {
        return sNo;
    }

    public void setsNo(Integer sNo) {
        this.sNo = sNo;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Character getSex() {
        return sex;
    }

    public void setSex(Character sex) {
        this.sex = sex;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public double getScore() {
        return score;
    }

    public void setScore(double score) {
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "sNo=" + sNo +
                ", name='" + name + '\'' +
                ", sex=" + sex +
                ", birthday=" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(birthday) +
                ", score=" + score +
                '}';
    }
}
